#include "ServerDialog.h"
#include "ui_ServerDialog.h"
#include "core/global.h"

ServerDialog::ServerDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ServerDialog)
{
    ui->setupUi(this);

    ui->serverName->setText(Config.value("game/serverName").toString());
    ui->serverPort->setText(Config.value("game/serverPort").toString());
    ui->playerNum->setValue(Config.value("game/playerNum").toInt());
}

ServerDialog::~ServerDialog(){
    Config.setValue("game/serverName", ui->serverName->text());
    Config.setValue("game/serverPort", ui->serverPort->text());
    Config.setValue("game/playerNum", ui->playerNum->value());

    delete ui;
}

bool ServerDialog::isFirstClient() const{
    return is_first_client;
}

void ServerDialog::setAsFirstClient(bool client){
    is_first_client = client;
}

void ServerDialog::on_buttonBox_accepted(){
    emit serverConfig(ui->serverPort->text().toUInt(), ui->serverName->text(), ui->playerNum->text().toInt());
}
